<template>
  <div class="register-container">
    <!-- 背景装饰 -->
    <div class="background-decoration">
      <div class="decoration-circle circle-1"></div>
      <div class="decoration-circle circle-2"></div>
      <div class="decoration-circle circle-3"></div>
    </div>

    <!-- 导航栏 -->
    <nav class="navbar">
      <div class="nav-content">
        <router-link to="/" class="logo">
          <h1>📝 Kosin</h1>
        </router-link>
        <div class="nav-links">
          <router-link to="/" class="nav-link">首页</router-link>
          <router-link to="/login" class="nav-link">登录</router-link>
        </div>
      </div>
    </nav>

    <!-- 注册表单区域 -->
    <div class="register-content">
      <div class="register-card">
        <div class="card-header">
          <div class="welcome-icon">🚀</div>
          <h2>加入 Kosin</h2>
          <p>创建您的免费账户，开启智能写作分析之旅</p>
        </div>

        <form @submit.prevent="handleRegister" class="register-form">
          <div class="form-group">
            <label for="username">用户名</label>
            <div class="input-wrapper">
              <svg class="input-icon" width="20" height="20" viewBox="0 0 24 24" fill="none">
                <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" stroke="currentColor" stroke-width="2"
                  stroke-linecap="round" stroke-linejoin="round" />
                <circle cx="12" cy="7" r="4" stroke="currentColor" stroke-width="2" />
              </svg>
              <input type="text" id="username" v-model="userStore.username" placeholder="请输入用户名" required
                :class="{ 'error': userStore.errorMessage }" />
            </div>
          </div>

          <div class="form-group">
            <label for="password">密码</label>
            <div class="input-wrapper">
              <svg class="input-icon" width="20" height="20" viewBox="0 0 24 24" fill="none">
                <rect x="3" y="11" width="18" height="11" rx="2" ry="2" stroke="currentColor" stroke-width="2" />
                <circle cx="12" cy="16" r="1" fill="currentColor" />
                <path d="M7 11V7a5 5 0 0 1 10 0v4" stroke="currentColor" stroke-width="2" />
              </svg>
              <input type="password" id="password" v-model="userStore.password" placeholder="请输入密码" required
                :class="{ 'error': userStore.errorMessage }" />
            </div>
          </div>

          <div class="form-group">
            <label for="phoneNumber">手机号</label>
            <div class="input-wrapper">
              <svg class="input-icon" width="20" height="20" viewBox="0 0 24 24" fill="none">
                <path
                  d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"
                  stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
              </svg>
              <input type="tel" id="phoneNumber" v-model="userStore.phoneNumber" placeholder="请输入手机号" required
                :class="{ 'error': userStore.errorMessage }" />
            </div>
          </div>

          <div v-if="userStore.errorMessage" class="error-message">
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none">
              <circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2" />
              <line x1="15" y1="9" x2="9" y2="15" stroke="currentColor" stroke-width="2" />
              <line x1="9" y1="9" x2="15" y2="15" stroke="currentColor" stroke-width="2" />
            </svg>
            {{ userStore.errorMessage }}
          </div>

          <button type="submit" :disabled="userStore.isLoading" class="register-button">
            <span v-if="userStore.isLoading" class="loading-spinner"></span>
            <span>{{ userStore.isLoading ? "注册中..." : "创建账户" }}</span>
            <svg v-if="!userStore.isLoading" width="20" height="20" viewBox="0 0 24 24" fill="none">
              <path d="M5 12h14M12 5l7 7-7 7" stroke="currentColor" stroke-width="2" stroke-linecap="round"
                stroke-linejoin="round" />
            </svg>
          </button>
        </form>

        <div class="card-footer">
          <p>已有账户？ <router-link to="/login" class="login-link">立即登录</router-link></p>
          <div class="divider">
            <span>或</span>
          </div>
          <router-link to="/ocr" class="guest-link">
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none">
              <path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4" stroke="currentColor" stroke-width="2"
                stroke-linecap="round" stroke-linejoin="round" />
              <polyline points="10,17 15,12 10,7" stroke="currentColor" stroke-width="2" stroke-linecap="round"
                stroke-linejoin="round" />
              <line x1="15" y1="12" x2="3" y2="12" stroke="currentColor" stroke-width="2" stroke-linecap="round"
                stroke-linejoin="round" />
            </svg>
            游客体验
          </router-link>
        </div>
      </div>

      <!-- 特色展示 -->
      <div class="benefits-showcase">
        <div class="benefit-item">
          <div class="benefit-icon">🎓</div>
          <h3>全学段支持</h3>
          <p>从小学到考研，全面覆盖各类写作需求</p>
        </div>
        <div class="benefit-item">
          <div class="benefit-icon">🔓</div>
          <h3>开源透明</h3>
          <p>完全开源的项目，算法透明可信</p>
        </div>
        <div class="benefit-item">
          <div class="benefit-icon">📈</div>
          <h3>持续改进</h3>
          <p>个性化学习路径，助力写作水平提升</p>
        </div>
        <div class="benefit-item">
          <div class="benefit-icon">⚡</div>
          <h3>快速分析</h3>
          <p>秒级响应，即时获得专业分析报告</p>
        </div>
      </div>
    </div>

    <!-- 服务条款提示 -->
    <div class="terms-notice">
      <p>注册即表示您同意我们的 <a href="#" class="terms-link">服务条款</a> 和 <a href="#" class="terms-link">隐私政策</a></p>
    </div>
  </div>
</template>

<script setup>
import UserStore from "../store/userStore";

const userStore = UserStore();

const handleRegister = () => {
  userStore.handleRegister();
};
</script>

<style scoped>
/* 全局样式重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.register-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
  position: relative;
  overflow: hidden;
}

/* 背景装饰 */
.background-decoration {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 1;
}

.decoration-circle {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  animation: float 6s ease-in-out infinite;
}

.circle-1 {
  width: 180px;
  height: 180px;
  top: 15%;
  right: 10%;
  animation-delay: 0s;
}

.circle-2 {
  width: 120px;
  height: 120px;
  top: 50%;
  left: 5%;
  animation-delay: 2s;
}

.circle-3 {
  width: 90px;
  height: 90px;
  bottom: 25%;
  right: 20%;
  animation-delay: 4s;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0px) scale(1);
  }

  50% {
    transform: translateY(-15px) scale(1.03);
  }
}

/* 导航栏 */
.navbar {
  position: relative;
  z-index: 10;
  padding: 1rem 0;
}

.nav-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: white;
  margin: 0;
}

.nav-links {
  display: flex;
  gap: 2rem;
}

.nav-link {
  text-decoration: none;
  color: rgba(255, 255, 255, 0.9);
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.nav-link:hover {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

/* 注册内容区域 */
.register-content {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: calc(100vh - 150px);
  padding: 2rem;
  position: relative;
  z-index: 5;
  gap: 4rem;
}

/* 注册卡片 */
.register-card {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 24px;
  padding: 3rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  width: 100%;
  max-width: 480px;
  animation: slideUp 0.6s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card-header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.welcome-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-10px);
  }
}

.card-header h2 {
  font-size: 2rem;
  font-weight: 700;
  color: #333;
  margin-bottom: 0.5rem;
}

.card-header p {
  color: #666;
  font-size: 1rem;
  line-height: 1.5;
}

/* 表单样式 */
.register-form {
  margin-bottom: 2rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  color: #333;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.input-wrapper {
  position: relative;
}

.input-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: #666;
  z-index: 1;
}

.input-wrapper input {
  width: 100%;
  padding: 1rem 1rem 1rem 3rem;
  border: 2px solid #e1e5e9;
  border-radius: 12px;
  font-size: 1rem;
  transition: all 0.3s ease;
  background: white;
}

.input-wrapper input:focus {
  outline: none;
  border-color: #3a86ff;
  box-shadow: 0 0 0 3px rgba(58, 134, 255, 0.1);
}

.input-wrapper input.error {
  border-color: #ff6b6b;
}

.input-wrapper input::placeholder {
  color: #999;
}

/* 错误消息 */
.error-message {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #ff6b6b;
  font-size: 0.9rem;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: rgba(255, 107, 107, 0.1);
  border-radius: 8px;
  border-left: 3px solid #ff6b6b;
}

/* 注册按钮 */
.register-button {
  width: 100%;
  padding: 1rem 2rem;
  background: linear-gradient(45deg, #28a745, #20c997);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 4px 20px rgba(40, 167, 69, 0.3);
}

.register-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(40, 167, 69, 0.4);
}

.register-button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* 卡片底部 */
.card-footer {
  text-align: center;
}

.card-footer p {
  color: #666;
  margin-bottom: 1.5rem;
}

.login-link {
  color: #3a86ff;
  text-decoration: none;
  font-weight: 600;
  transition: color 0.3s ease;
}

.login-link:hover {
  color: #2a76ef;
}

.divider {
  position: relative;
  margin: 1.5rem 0;
  text-align: center;
}

.divider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: #e1e5e9;
}

.divider span {
  background: white;
  padding: 0 1rem;
  color: #999;
  font-size: 0.9rem;
}

.guest-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: #666;
  text-decoration: none;
  font-weight: 500;
  padding: 0.75rem 1.5rem;
  border: 2px solid #e1e5e9;
  border-radius: 12px;
  transition: all 0.3s ease;
}

.guest-link:hover {
  color: #3a86ff;
  border-color: #3a86ff;
  background: rgba(58, 134, 255, 0.05);
}

/* 优势展示 */
.benefits-showcase {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
  max-width: 350px;
  margin-top: 2rem;
}

.benefit-item {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 1.5rem;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  animation: slideUp 0.6s ease-out;
  transition: transform 0.3s ease;
}

.benefit-item:hover {
  transform: translateY(-5px);
}

.benefit-item:nth-child(1) {
  animation-delay: 0.1s;
}

.benefit-item:nth-child(2) {
  animation-delay: 0.2s;
}

.benefit-item:nth-child(3) {
  animation-delay: 0.3s;
}

.benefit-item:nth-child(4) {
  animation-delay: 0.4s;
}

.benefit-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.benefit-item h3 {
  color: white;
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.benefit-item p {
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.85rem;
  line-height: 1.4;
}

/* 服务条款提示 */
.terms-notice {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  padding: 1rem 2rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  z-index: 10;
  font-size: 0.85rem;
  color: #666;
}

.terms-link {
  color: #3a86ff;
  text-decoration: none;
  font-weight: 500;
}

.terms-link:hover {
  text-decoration: underline;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .nav-content {
    padding: 0 1rem;
    flex-direction: column;
    gap: 1rem;
  }

  .register-content {
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    padding: 1rem;
  }

  .register-card {
    padding: 2rem;
    max-width: 100%;
  }

  .benefits-showcase {
    max-width: 100%;
    grid-template-columns: 1fr;
  }

  .card-header h2 {
    font-size: 1.5rem;
  }

  .circle-1,
  .circle-2,
  .circle-3 {
    display: none;
  }

  .terms-notice {
    position: relative;
    bottom: auto;
    left: auto;
    transform: none;
    margin: 2rem 1rem 0;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .register-card {
    padding: 1.5rem;
    border-radius: 16px;
  }

  .benefits-showcase {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .benefit-item {
    padding: 1rem;
  }
}
</style>
